/**
 * Created by Aron on 2-10-2014.
 */
function HomeViewModel(){
    var self = this;
    self.lang = new LanguageSystem();

    self.loginData = Array();
    self.loginData.username = ko.observable("");
    self.loginData.password = ko.observable("");


    self.init = function(){
        self.initCarousel();
    };

    self.login = function() {
        var result = false;
        $.getJSON("http://localhost:5841/api/users/"+self.loginData.username()+"/"+self.loginData.password(), function(data) {
            console.debug(data);
            result = data;
        });
        if ((self.loginData.password() != "" && self.loginData.username() != "" ) ) {
            window.location.href = 'landing.html';
        }
    };

    self.initCarousel = function() {
        var carousel1 = $('#carousel1');
        carousel1.carousel({
            interval: 4000
        });

        var clickEvent = false;

        carousel1.on('click', '.nav a', function () {
            clickEvent = true;
            $('.nav li').removeClass('active');
            $(this).parent().addClass('active');
        }).on('slid.bs.carousel', function (e) {
            if (!clickEvent) {
                var count = $('.nav').children().length - 1;
                var current = $('.nav li.active');
                current.removeClass('active').next().addClass('active');
                var id = parseInt(current.data('slide-to'));
                if (count == id) {
                    $('.nav li').first().addClass('active');
                }
            }
            clickEvent = false;
        });
    }


    self.init();
};
ko.applyBindings(new HomeViewModel());